#include <iostream>
#include <stack>
#include <string>
#include <unordered_map>

bool is_valid_brackets(const std::string& sequence) {
    std::stack<char> stack;
    std::unordered_map<char, char> bracket_pairs = {{')', '('}, {']', '['}, {'}', '{'}, {'>', '<'}};

    for (char bracket : sequence) {
        auto opening_bracket_it = bracket_pairs.find(bracket);
        if (opening_bracket_it != bracket_pairs.end()) {
            if (stack.empty() || stack.top() != opening_bracket_it->second) {
                return false;
            }
            stack.pop();
        } else {
            stack.push(bracket);
        }
    }
    return stack.empty();
}

int main() {
    std::string input_sequence;
    std::cout << "Введите скобочную последовательность: ";
    std::cin >> input_sequence;
    bool result = is_valid_brackets(input_sequence);
    std::cout << std::boolalpha << result << std::endl;
    return 0;
}
